﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using WalkingTec.Mvvm.Core;
using WalkingTec.Mvvm.Core.Extensions;
using Microsoft.EntityFrameworkCore;
using System.ComponentModel.DataAnnotations;
using HengTong.Model.Db;
using HengTong.Model.Db.Hr;


namespace HengTong.ViewModel.Person.SysPersonTrainBatcheVms
{
    public partial class SysPersonTrainBatcheListVm : BasePagedListVM<SysPersonTrainBatcheView, SysPersonTrainBatcheSearcher>
    {

        protected override IEnumerable<IGridColumn<SysPersonTrainBatcheView>> InitGridHeader()
        {
            return new List<GridColumn<SysPersonTrainBatcheView>>{
                this.MakeGridHeader(x => x.TrainName),
                this.MakeGridHeader(x => x.TrainStartDate),
                this.MakeGridHeader(x => x.TrainEndDate),
                this.MakeGridHeader(x => x.ExamDate),
                this.MakeGridHeaderAction(width: 200)
            };
        }

        public override IOrderedQueryable<SysPersonTrainBatcheView> GetSearchQuery()
        {
            var query = DC.Set<SysPersonTrainBatche>()
                .CheckContain(Searcher.TrainName, x=>x.TrainName)
                .CheckBetween(Searcher.TrainStartDate?.GetStartTime(), Searcher.TrainStartDate?.GetEndTime(), x => x.TrainStartDate, includeMax: false)
                .CheckBetween(Searcher.TrainEndDate?.GetStartTime(), Searcher.TrainEndDate?.GetEndTime(), x => x.TrainEndDate, includeMax: false)
                .CheckBetween(Searcher.ExamDate?.GetStartTime(), Searcher.ExamDate?.GetEndTime(), x => x.ExamDate, includeMax: false)
                .Select(x => new SysPersonTrainBatcheView
                {
				    ID = x.ID,
                    TrainName = x.TrainName,
                    TrainStartDate = x.TrainStartDate,
                    TrainEndDate = x.TrainEndDate,
                    ExamDate = x.ExamDate,
                })
                .OrderBy(x => x.ID);
            return query;
        }

    }

    public class SysPersonTrainBatcheView : SysPersonTrainBatche{

    }
}
